/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.facilscrum.form.issues;

import java.awt.Color;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.facilscrum.beans.Equiposusuarios;
import org.facilscrum.beans.Estatus;
import org.facilscrum.beans.Issues;
import org.facilscrum.beans.Issuescomentarios;
import org.facilscrum.beans.Prioridad;
import org.facilscrum.beans.Tipo;
import org.facilscrum.beans.Usuarios;
import org.facilscrum.controller.EquiposusuariosController;
import org.facilscrum.controller.EstatusController;
import org.facilscrum.controller.IssuesController;
import org.facilscrum.controller.IssuescomentariosController;
import org.facilscrum.controller.PrioridadController;
import org.facilscrum.controller.TipoController;
import org.facilscrum.controller.UsuariosController;
import org.facilscrum.generales.Mensajeria;
import org.facilscrum.sesion.MySesion;
import org.javscaz.javscaztools.utilidades.Utilidades;

/**
 *
 * @author avbravo
 */
public class IssuesComentariosForm extends javax.swing.JInternalFrame {

    EquiposusuariosController equiposusuariosController = new EquiposusuariosController();
    Estatus estatus = new Estatus();
    EstatusController estatusController = new EstatusController();
    Issues issues = new Issues();
    IssuesController issuesController = new IssuesController();
    Issuescomentarios issuescomentarios = new Issuescomentarios();
    IssuescomentariosController issuescomentariosController = new IssuescomentariosController();
    Prioridad prioridad = new Prioridad();
    PrioridadController prioridadController = new PrioridadController();
    Tipo tipo = new Tipo();
    TipoController tipoController = new TipoController();
    UsuariosController usuariosController = new UsuariosController();
    Usuarios usuarios = new Usuarios();
    DefaultTableModel modelo, modeloComentarios;
//Integer idissues;
    /**
     * Creates new form UsuariosForm
     */
    public IssuesComentariosForm() {
        initComponents();
        modelo = (DefaultTableModel) jTableIssues.getModel();
         modeloComentarios = (DefaultTableModel) jTableComentarios.getModel();
        if (!MySesion.getSeleccionoProyectoTrabajo()) {
            Mensajeria.MensajeWarning("Debe indicar el proyecto de trabajo");
        } else {
            String where = "idproyecto='" + MySesion.getProyectos().getIdproyecto() + "' order by idissues";
            cargarTablaIssues(where);
            jTextFieldProyecto.setText(MySesion.getProyectos().getProyecto());
        }
        jTableIssues.setAutoCreateRowSorter(true);

      if (cargarPrioridad() && cargarTipo() && cargarEstatus() && cargarReporta() && cargarUsuarios()) {
          
      }
        TableColumn editarColumna = jTableIssues.getColumnModel().getColumn(4);
//     
        TableColumn columnId = jTableIssues.getColumnModel().getColumn(0);
        columnId.setPreferredWidth(10);
        TableColumn columnTitulo = jTableIssues.getColumnModel().getColumn(1);
        columnTitulo.setPreferredWidth(250);
        TableColumn columnTipo = jTableIssues.getColumnModel().getColumn(2);
        columnTipo.setPreferredWidth(50);
        TableColumn columnPrioridad = jTableIssues.getColumnModel().getColumn(3);
        columnPrioridad.setPreferredWidth(50);

        TableColumn columnEstatus = jTableIssues.getColumnModel().getColumn(4);
        columnEstatus.setPreferredWidth(50);
        TableColumn columnReportado = jTableIssues.getColumnModel().getColumn(5);
        columnReportado.setPreferredWidth(150);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialogComentarios = new javax.swing.JDialog();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldIdissues = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldTitulo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaComentario = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jComboBoxReporta = new javax.swing.JComboBox();
        jButtonGuardar = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTableComentarios = new javax.swing.JTable();
        buttonGroupReporta = new javax.swing.ButtonGroup();
        buttonGroupTecnico = new javax.swing.ButtonGroup();
        buttonGroupFiltros = new javax.swing.ButtonGroup();
        buttonGroupHaceComentarios = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jButtonCerrar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldProyecto = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableIssues = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jCheckBoxTipo = new javax.swing.JCheckBox();
        jCheckBoxEstatus = new javax.swing.JCheckBox();
        jComboBoxFiltroTipo = new javax.swing.JComboBox();
        jComboBoxFiltroPrioridad = new javax.swing.JComboBox();
        jCheckBoxPrioridad = new javax.swing.JCheckBox();
        jCheckBoxReportado = new javax.swing.JCheckBox();
        jComboBoxFiltroReporta = new javax.swing.JComboBox();
        jCheckBoxAsignado = new javax.swing.JCheckBox();
        jComboBoxFiltroAsignado = new javax.swing.JComboBox();
        jComboBoxFiltroEstatus = new javax.swing.JComboBox();
        jButtonFiltrar = new javax.swing.JButton();
        jCheckBoxMostrarTodos = new javax.swing.JCheckBox();
        jCheckBoxFiltrar = new javax.swing.JCheckBox();

        jDialogComentarios.setTitle("Comentarios");

        jLabel1.setText("Id");

        jTextFieldIdissues.setEditable(false);

        jLabel2.setText("Titulo");

        jTextFieldTitulo.setEnabled(false);
        jTextFieldTitulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldTituloActionPerformed(evt);
            }
        });

        jLabel4.setText("Comentario");

        jTextAreaComentario.setColumns(20);
        jTextAreaComentario.setRows(5);
        jScrollPane2.setViewportView(jTextAreaComentario);

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/facilscrum/gif/Save.png"))); // NOI18N
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/facilscrum/gif/return.png"))); // NOI18N
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jLabel5.setText("Quien comenta");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxReporta, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxReporta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonGuardar)
                    .addComponent(jButtonRegresar))
                .addContainerGap())
        );

        jTableComentarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Id", "Fecha", "Hora", "Comentario", "Emisor"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(jTableComentarios);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(92, 92, 92)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldIdissues, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 425, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 652, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel4)
                        .addComponent(jLabel2))
                    .addContainerGap(530, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldIdissues, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextFieldTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(56, 56, 56)
                    .addComponent(jLabel2)
                    .addGap(22, 22, 22)
                    .addComponent(jLabel4)
                    .addContainerGap(470, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout jDialogComentariosLayout = new javax.swing.GroupLayout(jDialogComentarios.getContentPane());
        jDialogComentarios.getContentPane().setLayout(jDialogComentariosLayout);
        jDialogComentariosLayout.setHorizontalGroup(
            jDialogComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jDialogComentariosLayout.setVerticalGroup(
            jDialogComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        setClosable(true);
        setTitle("Comentarios de  Issues");
        setToolTipText("");

        jButtonCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/avbravo/jscrum/gif/return.gif"))); // NOI18N
        jButtonCerrar.setToolTipText("Cerrar");
        jButtonCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCerrarActionPerformed(evt);
            }
        });

        jLabel3.setText("Proyecto");

        jTextFieldProyecto.setEnabled(false);

        jTableIssues.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "Titulo", "Tipo", "Prioridad", "Estatus", "Reportado", "Creado", "Tecnico"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableIssues.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableIssuesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableIssues);

        jLabel9.setForeground(java.awt.Color.blue);
        jLabel9.setText("Haga clic en la columna para agregar comentarios");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtrar por"));

        jCheckBoxTipo.setText("Tipo");
        jCheckBoxTipo.setEnabled(false);

        jCheckBoxEstatus.setText("Estatus");
        jCheckBoxEstatus.setEnabled(false);

        jComboBoxFiltroTipo.setEnabled(false);

        jComboBoxFiltroPrioridad.setEnabled(false);

        jCheckBoxPrioridad.setText("Prioridad");
        jCheckBoxPrioridad.setEnabled(false);
        jCheckBoxPrioridad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxPrioridadActionPerformed(evt);
            }
        });

        jCheckBoxReportado.setText("Reporta");
        jCheckBoxReportado.setEnabled(false);
        jCheckBoxReportado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxReportadoActionPerformed(evt);
            }
        });

        jComboBoxFiltroReporta.setEnabled(false);

        jCheckBoxAsignado.setText("Asignado");
        jCheckBoxAsignado.setEnabled(false);
        jCheckBoxAsignado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxAsignadoActionPerformed(evt);
            }
        });

        jComboBoxFiltroAsignado.setEnabled(false);

        jComboBoxFiltroEstatus.setEnabled(false);

        jButtonFiltrar.setText("Filtrar");
        jButtonFiltrar.setEnabled(false);
        jButtonFiltrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFiltrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBoxEstatus)
                    .addComponent(jCheckBoxTipo)
                    .addComponent(jCheckBoxPrioridad))
                .addGap(26, 26, 26)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBoxFiltroEstatus, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxFiltroTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxFiltroPrioridad, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jCheckBoxReportado)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jComboBoxFiltroReporta, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButtonFiltrar)
                        .addGroup(jPanel5Layout.createSequentialGroup()
                            .addComponent(jCheckBoxAsignado)
                            .addGap(18, 18, 18)
                            .addComponent(jComboBoxFiltroAsignado, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(195, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBoxEstatus)
                    .addComponent(jCheckBoxReportado)
                    .addComponent(jComboBoxFiltroReporta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxFiltroEstatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jCheckBoxAsignado)
                        .addComponent(jComboBoxFiltroAsignado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jCheckBoxTipo))
                    .addComponent(jComboBoxFiltroTipo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCheckBoxPrioridad)
                            .addComponent(jButtonFiltrar)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jComboBoxFiltroPrioridad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        buttonGroupFiltros.add(jCheckBoxMostrarTodos);
        jCheckBoxMostrarTodos.setSelected(true);
        jCheckBoxMostrarTodos.setText("Mostrar todos");
        jCheckBoxMostrarTodos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMostrarTodosActionPerformed(evt);
            }
        });

        buttonGroupFiltros.add(jCheckBoxFiltrar);
        jCheckBoxFiltrar.setText("Filtrar");
        jCheckBoxFiltrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxFiltrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jCheckBoxMostrarTodos)
                        .addGap(31, 31, 31)
                        .addComponent(jCheckBoxFiltrar)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 920, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldProyecto))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap())))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(260, 260, 260)
                .addComponent(jButtonCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCheckBoxMostrarTodos)
                            .addComponent(jCheckBoxFiltrar)))
                    .addComponent(jTextFieldProyecto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCerrarActionPerformed
        dispose();
    }//GEN-LAST:event_jButtonCerrarActionPerformed

    private void jTableIssuesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableIssuesMouseClicked
        jTextFieldIdissues.setText(jTableIssues.getValueAt(jTableIssues.getSelectedRow(), 0).toString());
        issues.setIdissues(Integer.parseInt(jTextFieldIdissues.getText()));
        Issues is = issuesController.findByPrimaryKey(issues);

        if (is == null) {
            Mensajeria.MensajeWarning("No existe un issues con ese id");
            return;
        }
        issues = is;
        jTextAreaComentario.setText("");
        jTextFieldTitulo.setText(issues.getTitulo());

        Usuarios u = new Usuarios();
        UsuariosController uc = new UsuariosController();
        u.setUsername(issues.getUsername());
        u = uc.findByPrimaryKey(u);
        if (u != null) {
            jComboBoxReporta.setSelectedItem(u.getNombre() + " - " + u.getCedula());
        } else {
            //Mensajeria.Mensaje("No existe un usuario con ese username" + issues.getUsername());
        }

cargarTablaComentarios(issues.getIdissues());

        jDialogComentarios.setSize(642, 625); //Antes (764, 350)
        jDialogComentarios.setLocation(150, 100);
        jDialogComentarios.setVisible(true);
    }//GEN-LAST:event_jTableIssuesMouseClicked

    private void jTextFieldTituloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldTituloActionPerformed
    }//GEN-LAST:event_jTextFieldTituloActionPerformed

    private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed
        jDialogComentarios.dispose();
    }//GEN-LAST:event_jButtonRegresarActionPerformed

    private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed
        try {
            if (!guiToData()) {
                return;
            }
            if (issuescomentariosController.insert(issuescomentarios)) {
            
                //String where = "idproyecto='" + MySesion.getProyectos().getIdproyecto() + "' order by idissues";
                cargarTablaComentarios(issues.getIdissues());
                jTextAreaComentario.setText("");
            } else {
                Mensajeria.MensajeWarning("No se pudo editar" + issuesController.getMensaje());
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "guardar()");
        }
    }//GEN-LAST:event_jButtonGuardarActionPerformed

    private void jCheckBoxPrioridadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxPrioridadActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxPrioridadActionPerformed

    private void jCheckBoxReportadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxReportadoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxReportadoActionPerformed

    private void jCheckBoxAsignadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxAsignadoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxAsignadoActionPerformed

    private void jCheckBoxFiltrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxFiltrarActionPerformed
        habilitarFiltro(true);
    }//GEN-LAST:event_jCheckBoxFiltrarActionPerformed

    private void jCheckBoxMostrarTodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMostrarTodosActionPerformed
        String where;
        where = "idproyecto='" + MySesion.getProyectos().getIdproyecto() + "' order by idissues";
        cargarTablaIssues(where);
        habilitarFiltro(false);
    }//GEN-LAST:event_jCheckBoxMostrarTodosActionPerformed

    private void jButtonFiltrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFiltrarActionPerformed
        try {
            String where;
            if (jCheckBoxMostrarTodos.isSelected()) {
                where = "idproyecto='" + MySesion.getProyectos().getIdproyecto() + "' order by idissues";
                cargarTablaIssues(where);
            } else {
                where = "idproyecto='" + MySesion.getProyectos().getIdproyecto() + "'";

                int j;

                if (jCheckBoxEstatus.isSelected()) {
                    j = jComboBoxFiltroEstatus.getSelectedIndex();
                    if (j != -1) {
                        Estatus e = estatusController.getEstatuslist().get(j);
                        where += " and idestatus='" + e.getIdestatus() + "'";
                    } else {
                        Mensajeria.Mensaje("No se ha seleccionado ningun estatus");

                    }
                }
                if (jCheckBoxTipo.isSelected()) {
                    j = jComboBoxFiltroTipo.getSelectedIndex();
                    if (j != -1) {
                        Tipo t = tipoController.getTipolist().get(j);
                        where += " and idtipo='" + t.getIdtipo() + "'";
                    } else {
                        Mensajeria.Mensaje("No se ha seleccionado ningun tipo");

                    }
                }
                if (jCheckBoxPrioridad.isSelected()) {
                    j = jComboBoxFiltroPrioridad.getSelectedIndex();
                    if (j != -1) {
                        Prioridad p = prioridadController.getPrioridadlist().get(j);
                        where += " and idprioridad='" + p.getIdprioridad() + "'";
                    } else {
                        Mensajeria.Mensaje("No se ha seleccionado ninguna prioridad");

                    }
                }
                if (jCheckBoxReportado.isSelected()) {
                    j = jComboBoxFiltroReporta.getSelectedIndex();
                    if (j != -1) {
                        Usuarios u = usuariosController.getUsuarioslist().get(j);
                        where += " and username='" + u.getUsername() + "'";
                    } else {
                        Mensajeria.Mensaje("No se ha seleccionado ningun usuario que reporta");

                    }
                }
                if (jCheckBoxAsignado.isSelected()) {
                    int k = jComboBoxFiltroAsignado.getSelectedIndex();
                    if (k != -1) {

                        Equiposusuarios e = equiposusuariosController.getEquiposusuarioslist().get(k);
                        where += " and usernameasignado='" + e.getUsername() + "'";

                    } else {
                        Mensajeria.Mensaje("No se ha seleccionado ningun tecnico");

                    }
                }
                where += " order by idissues";
             
                cargarTablaIssues(where);
            }

        } catch (Exception ex) {
            Mensajeria.MensajeWarning("filtar()");
        }
    }//GEN-LAST:event_jButtonFiltrarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupFiltros;
    private javax.swing.ButtonGroup buttonGroupHaceComentarios;
    private javax.swing.ButtonGroup buttonGroupReporta;
    private javax.swing.ButtonGroup buttonGroupTecnico;
    private javax.swing.JButton jButtonCerrar;
    private javax.swing.JButton jButtonFiltrar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JCheckBox jCheckBoxAsignado;
    private javax.swing.JCheckBox jCheckBoxEstatus;
    private javax.swing.JCheckBox jCheckBoxFiltrar;
    private javax.swing.JCheckBox jCheckBoxMostrarTodos;
    private javax.swing.JCheckBox jCheckBoxPrioridad;
    private javax.swing.JCheckBox jCheckBoxReportado;
    private javax.swing.JCheckBox jCheckBoxTipo;
    private javax.swing.JComboBox jComboBoxFiltroAsignado;
    private javax.swing.JComboBox jComboBoxFiltroEstatus;
    private javax.swing.JComboBox jComboBoxFiltroPrioridad;
    private javax.swing.JComboBox jComboBoxFiltroReporta;
    private javax.swing.JComboBox jComboBoxFiltroTipo;
    private javax.swing.JComboBox jComboBoxReporta;
    private javax.swing.JDialog jDialogComentarios;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTableComentarios;
    private javax.swing.JTable jTableIssues;
    private javax.swing.JTextArea jTextAreaComentario;
    private javax.swing.JTextField jTextFieldIdissues;
    private javax.swing.JTextField jTextFieldProyecto;
    private javax.swing.JTextField jTextFieldTitulo;
    // End of variables declaration//GEN-END:variables

    private void habilitarFiltro(Boolean b) {
        jCheckBoxEstatus.setEnabled(b);
        jCheckBoxTipo.setEnabled(b);
        jCheckBoxPrioridad.setEnabled(b);
        jCheckBoxReportado.setEnabled(b);
        jCheckBoxAsignado.setEnabled(b);
        jComboBoxFiltroEstatus.setEnabled(b);
        jComboBoxFiltroTipo.setEnabled(b);
        jComboBoxFiltroPrioridad.setEnabled(b);
        jComboBoxFiltroReporta.setEnabled(b);
        jComboBoxFiltroAsignado.setEnabled(b);
        jButtonFiltrar.setEnabled(b);
        if (!b) {
            jCheckBoxEstatus.setSelected(false);
            jCheckBoxTipo.setSelected(false);
            jCheckBoxPrioridad.setSelected(false);
            jCheckBoxReportado.setSelected(false);
            jCheckBoxAsignado.setSelected(false);
        }

    }



    private void cargarTablaIssues(String where) {
        try {

            modelo = Utilidades.limpiarModelo(modelo);
//            String where = "idproyecto='" + MySesion.getProyectos().getIdproyecto() + "' order by idissues";
            if (issuesController.query(where)) {
                for (Issues i : issuesController.getIssueslist()) {
                    Object[] filas = new Object[8]; // Hay tres columnas en la tabla       
                    filas[0] = i.getIdissues();
                    filas[1] = i.getTitulo();
                    filas[2] = i.getTipo().getTipo();
                    filas[3] = i.getPrioridad().getPrioridad();
                    filas[4] = i.getEstatus().getEstatus();
                    filas[5] = i.getUsuarios().getNombre();
                    filas[6] = MySesion.formatearFechaToString(i.getFecha());
                    Usuarios u = new Usuarios();
                    UsuariosController uc = new UsuariosController();
                    u.setUsername(i.getUsernameasignado());
                    if (uc.findByUsername(u)) {
                        filas[7] = uc.getUsuarioslist().get(0).getNombre();
                    } else {
                        filas[7] = "";
                    }


                    modelo.addRow(filas);
                }
            }

        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarTablaUserStoriesAsignados()");
        }
    }

      private void cargarTablaComentarios(Integer idissues) {
        try {

            modeloComentarios = Utilidades.limpiarModelo(modeloComentarios);
           String where = "idissues='" + idissues + "' order by fecha";
            if (issuescomentariosController.query(where)) {
                for (Issuescomentarios i : issuescomentariosController.getIssuescomentarioslist()) {
                    Object[] filas = new Object[5]; // Hay tres columnas en la tabla       
                    filas[0] = i.getIdissuescomentario();
                    filas[1] = MySesion.formatearFechaToString(i.getFecha());
                    filas[2] = i.getHora();
                    filas[3] = i.getComentario();
                    filas[4] = i.getUsuarios().getNombre();
                    modeloComentarios.addRow(filas);
                }
            }

        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarTablaUserStoriesAsignados()");
        }
    }

   

    private Boolean guiToData() {
        try {
            if (jTextFieldTitulo.getText() == null || jTextFieldTitulo.getText().equals("")) {
                Mensajeria.Mensaje("El username no debe estar vacio");
                return false;
            }


            if (jTextAreaComentario.getText().equals("")) {
                Mensajeria.Mensaje("Ingrese la descripcion");
                return false;
            }

       int     j = jComboBoxReporta.getSelectedIndex();
            if (j != -1) {
                Usuarios u = usuariosController.getUsuarioslist().get(j);
                issuescomentarios.setUsername(u.getUsername());
            } else {
                Mensajeria.Mensaje("No se ha seleccionado ningun usuario que reporta");
                return false;
            }

            issuescomentarios.setIdissues(issues.getIdissues());
             issuescomentarios.setComentario(jTextAreaComentario.getText());
             issuescomentarios.setFecha(MySesion.getFechausername());
            issuescomentarios.setHora(MySesion.getHoraSistema());
            return true;
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "guiToData()");
        }
        return false;
    }

     private Boolean cargarEstatus() {
        try {
            jComboBoxFiltroEstatus.removeAllItems();
            if (estatusController.selectAll()) {
                for (Estatus e : estatusController.getEstatuslist()) {
                    jComboBoxFiltroEstatus.addItem(e.getEstatus());
                }
                return true;
            } else {
                Mensajeria.Mensaje("Debe crear primero los estatus");
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarEstatus() ");

        }
        return false;
    }

    private Boolean cargarTipo() {
        try {
            jComboBoxFiltroTipo.removeAllItems();
            if (tipoController.selectAll()) {
                for (Tipo t : tipoController.getTipolist()) {
                    jComboBoxFiltroTipo.addItem(t.getTipo());
                }
                return true;
            } else {
                Mensajeria.Mensaje("Debe crear primero los tipos");
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarTipo() ");

        }
        return false;
    }

    private Boolean cargarPrioridad() {
        try {
       
            jComboBoxFiltroPrioridad.removeAllItems();
            if (prioridadController.selectAll()) {
                for (Prioridad p : prioridadController.getPrioridadlist()) {
                    jComboBoxFiltroPrioridad.addItem(p.getPrioridad());
                }
                return true;
            } else {
                Mensajeria.Mensaje("Debe crear primero las prioridades");
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarPrioridad() ");

        }
        return false;
    }
    private Boolean cargarUsuarios() {
        try {

          
            jComboBoxFiltroAsignado.removeAllItems();
            String sql = "idequipo='" + MySesion.getProyectos().getIdequipo() + "'";
            if (equiposusuariosController.query(sql)) {
                for (Equiposusuarios eu : equiposusuariosController.getEquiposusuarioslist()) {
                  
                    jComboBoxFiltroAsignado.addItem(eu.getUsuarios().getNombre() + " - " + eu.getUsuarios().getCedula());
                }
                return true;
            } else {
                Mensajeria.MensajeWarning("No hay usuarios asignados al equipo de este proyecto");
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarUsuarios() ");
        }
        return false;
    }

    private Boolean cargarReporta() {
        try {

            jComboBoxReporta.removeAllItems();
            jComboBoxFiltroReporta.removeAllItems();
            if (usuariosController.selectAll()) {
                for (Usuarios u : usuariosController.getUsuarioslist()) {
                    jComboBoxReporta.addItem(u.getNombre() + " - " + u.getCedula());
                    jComboBoxFiltroReporta.addItem(u.getNombre() + " - " + u.getCedula());
                }
                return true;
            } else {
                Mensajeria.MensajeWarning("No hay usuarios ");
            }
        } catch (Exception ex) {
            Mensajeria.MensajeError(ex, "cargarReporta()");
        }
        return false;
    }
}
